from character import Character
from game import Game
from skill.skill import Skill
from game.movement import MovementInstruction
from game.map import direction

class Effect:
    '''
    describe the effect caused by a skill,
    including hp damage, mp damage and meta effects such as appending passive skills
    '''
    def __init__(self, owned_by_skill:Skill, hp_damage=0, mp_damage=0, meta_effects=[]):
        '''
        :param damage:
        :param mp_damage:
        :param meta_effects: list of objects generated by skills and passive skills;
            each object can be called directly to execute the effects
        '''
        self.skill = owned_by_skill
        self.hp_damage = hp_damage
        self.mp_damage = mp_damage
        self.meta_effects = meta_effects

    def __call__(self, target_character:Character, game:Game):
        target_character.hp -= self.hp_damage
        target_character.mp -= self.mp_damage
        for meta_effect in self.meta_effects:
            meta_effect(self.skill, target_character, game)

    def gen_effect_str(self, target_character:Character, game:Game):
        base_effect_str = f'{self.skill.owner.name} [{self.skill.name}]\nMP: [-{self.skill.mp_cost}]{self.skill.owner.mp}\n>>>{target_character.name}\n'
        if self.hp_damage > 0:
            base_effect_str += f'HP: [-{self.hp_damage}]{target_character.hp}\n'
        if self.mp_damage > 0:
            base_effect_str += f'MP: [-{self.mp_damage}]{target_character.mp}\n'
        for meta_effect in self.meta_effects:
            base_effect_str += meta_effect.gen_effect_str()
        return base_effect_str

class MetaEffect():
    def __init__(self, owned_by_skill:Skill):
        self.skill = owned_by_skill
    def __call__(self, target_character:Character, game:Game):
        # The following is just an example
        # target_character.set_movement_instruction(MovementInstruction(direction.RIGHT, 1))
        # besides, you have the access to self.skill, which shows the owner and owner_skill of this meta_effect
        pass
    def gen_effect_str(self):
        return 'This is a dummy effect'

class MovementHitEffect(Effect):
    pass